﻿namespace star_questionnair.Models.Enum;

using System;

public enum QuestionEnum
{
    SingleChoice,
    MultipleChoice,
    ShortAnswer,
    Dropdown,
    Textarea,
    SortQuestion,
    LevelQuestion,
    FileQuestion
}

public static class QuestionEnumExtensions
{
    public static string GetType(this QuestionEnum questionEnum)
    {
        return questionEnum switch
        {
            QuestionEnum.SingleChoice => "Singlechoice",
            QuestionEnum.MultipleChoice => "Multiplechoice",
            QuestionEnum.ShortAnswer => "Shortanswer",
            QuestionEnum.Dropdown => "Dropdown",
            QuestionEnum.Textarea => "Textarea",
            QuestionEnum.SortQuestion => "Sortquestion",
            QuestionEnum.LevelQuestion => "Levelquestion",
            QuestionEnum.FileQuestion => "filequestion",
            _ => throw new ArgumentOutOfRangeException(nameof(questionEnum), questionEnum, null)
        };
    }

    public static QuestionEnum FromType(string type)
    {
        foreach (QuestionEnum questionEnum in Enum.GetValues(typeof(QuestionEnum)))
        {
            if (questionEnum.ToString().Equals(type, StringComparison.OrdinalIgnoreCase))
            {
                return questionEnum;
            }
        }
        throw new ArgumentException($"Unknown type: {type}", nameof(type));
    }


    public static bool IsTextType(string type) =>
        FromType(type) == QuestionEnum.ShortAnswer || FromType(type) == QuestionEnum.Textarea;

    public static bool IsChoiceType(string type) =>
        FromType(type) == QuestionEnum.SingleChoice ||
        FromType(type) == QuestionEnum.MultipleChoice ||
        FromType(type) == QuestionEnum.Dropdown;

    public static bool IsSortType(string type) => FromType(type) == QuestionEnum.SortQuestion;

    public static bool IsLevelType(string type) => FromType(type) == QuestionEnum.LevelQuestion;

    public static bool IsFileType(string type) => FromType(type) == QuestionEnum.FileQuestion;
}
